package messageHistoryDao

import (
	"chart.zozoo.net/app/models"
	"chart.zozoo.net/core/mysql"
	"errors"
	"gorm.io/gorm"
)

// GetByUuid 根据uuid获取用户聊天历史
func GetByUuid(uid int, fUuid string) (m *models.MessageHistory, err error) {
	m = new(models.MessageHistory)
	res := mysql.MysqlClient.
		Select("id,f_uuid,msg_view,unread_num,created_at").
		Where("uid=? and f_uuid = ?", uid, fUuid).
		Find(m)
	if res.Error != nil && !errors.Is(res.Error, gorm.ErrRecordNotFound) {
		return nil, res.Error
	}

	return m, nil
}
